export class TreeNode {
    val: number;
    left: TreeNode | null;
    right: TreeNode | null;
    constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
        this.val = val === undefined ? 0 : val;
        this.left = left === undefined ? null : left;
        this.right = right === undefined ? null : right;
    }
}
function pathSum(root: TreeNode | null, targetSum: number): number {
    let count = 0;
    const dfs = (node: TreeNode | null, target: number, path: number) => {
        if (!node) return;
        path += node.val;
        if (path === target) count++;
        dfs(node.left, target, path);
        dfs(node.right, target, path);
        path -= node.val;
    }
    dfs(root, targetSum, 0);
    return count;

};